#pragma once
#include "basic_window.hpp"
#include "paint_dc.hpp"
#include "string_converter.hpp"
#include "draw_utils.hpp"
#include "font.hpp"

namespace winboost {
   namespace windows {
      namespace controls {

class label : public basic_window
{
public:

   label(void);
   virtual ~label(void);

   Gdiplus::Color get_background_color() const { return m_background; }
   void set_background_color(Gdiplus::Color val) { m_background = val; }
   resources::font& font(void) const { return const_cast<resources::font&>(m_font); }

private:
   Gdiplus::Color m_background;
   resources::font m_font;

   LRESULT on_paint(const winboost::events::message& e);
};

//-------------------------------------
// Implementation.
//-------------------------------------
inline label::label(void)
{
   m_background.SetFromCOLORREF(::GetSysColor(COLOR_3DFACE));
   set_message_handler(WM_PAINT, boost::bind(&label::on_paint, this, _1));
}

inline label::~label(void)
{
}

inline LRESULT label::on_paint(const winboost::events::message& e)
{
   winboost::dc::paint dc(this);
   RECT rc = {0};
   ::GetClientRect(handle(), &rc);
   Gdiplus::RectF rect = detail::draw_utils::rectf_from_rct(rc);   

   Gdiplus::Graphics g(dc.get_hdc());

   Gdiplus::SolidBrush  brush_back(m_background);
   g.FillRectangle(&brush_back, rect);

   u_string s = get_window_text();
   std::wstring text = detail::string_converter::to_wstr(s);

   m_font.reset();

   g.SetTextRenderingHint(Gdiplus::TextRenderingHintSystemDefault);
   g.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);
   g.DrawString(text.c_str(), -1, m_font.get_font(), rect, m_font.get_format(), m_font.get_brush());
   return 0;
}

      }
   }
}


